// 查询字典表类型 dicts
export default {
    data() {
        return {
            dicts: {
                // 风险类別
                riskCategory: this.$store.getters.riskCategory,
                // 风险类型
                riskType: this.$store.getters.riskType,
                // 风险等级
                riskLevel: this.$store.getters.riskLevel,
                // 风险处理时长
                riskDisposeDate: this.$store.getters.riskDisposeDate,
                // 风险详情描述
                riskDetails: this.$store.getters.riskDetails,
                // 产品类型类别
                productType: this.$store.getters.productType,
                // 来源渠道
                sourceType: this.$store.getters.sourceType,
                // 机构简称
                orgType: this.$store.getters.orgType,
                // 案件类型
                caseType: this.$store.getters.caseType,
                // 案件状态
                caseStatus: this.$store.getters.caseStatus,
                // 线索状态
                clueStatus: this.$store.getters.clueStatus
            },
            riskCategoryForm: {},
            // 风险类型(risk_type)
            riskTypeList: [],
            riskTypeForm: {},
            // 风险等级(risk_level)
            riskLevelList: [],
            riskLevelForm: {},
            // 风险处理时长
            riskDisposeDateList: [],
            riskDisposeDateForm: {},
            // 风险详情描述
            riskDetailsList: [],
            riskDetailsForm: {}
        }
    },
    methods: {
        // 风险类別change
        riskCategoryChange(val) {
            this.riskTypeList = []
            this.riskTypeForm = {}
            this.riskLevelList = []
            this.riskLevelForm = {}
            this.riskDisposeDateList = []
            this.riskDisposeDateForm = {}
            this.riskDetailsList = []
            this.riskDetailsForm = {}
            if (val) {
                this.queryRiskDict('risk_type', val)
            }
        },
        // 风险类型change
        riskTypeChange(val) {
            this.riskLevelList = []
            this.riskLevelForm = {}
            this.riskDisposeDateList = []
            this.riskDisposeDateForm = {}
            this.riskDetailsList = []
            this.riskDetailsForm = {}
            if (val) {
                let _category = this.dicts.riskCategory.find(item => item.id == this.riskCategoryForm.id)
                let _type = this.dicts.riskType.find(item => item.value == val)
                if (_category && _type) {
                    this.queryRiskDict('risk_level', _category.parentId)
                    this.queryRiskDict('risk_details', _type.id)
                }
            }
        },
        // 风险等级change
        riskLevelChange(val) {
            this.riskDisposeDateList = []
            this.riskDisposeDateForm = {}
            if (val) {
                let _level = this.dicts.riskLevel.find(item => item.value == val)
                if (_level.name == 'A级') {
                    this.riskDisposeDateList.push(this.dicts.riskDisposeDate[0])
                }
                else if (_level.name == 'B级' || _level.name == 'C级' || _level.name == 'S级') {
                    this.riskDisposeDateList.push(this.dicts.riskDisposeDate[1])
                }
                else {
                    this.riskDisposeDateList = this.dicts.riskDisposeDate
                }
            }
        },
        // 查询风险 
        queryRiskDict(type, parentId) {
            let _param = {
                type: type
            }
            if (type == 'risk_type') {
                _param.parentId = parentId
            }
            else if (type == 'risk_level') {
                _param.id = parentId
            }
            else if (type == 'risk_details') {
                _param.parentId = parentId
            }
            api.queryDict(_param).then(res => {
                if (type == 'risk_type') {
                    this.riskTypeList = res.list
                }
                else if (type == 'risk_level') {
                    this.riskLevelList = res.list
                }
                else if (type == 'risk_details') {
                    this.riskDetailsList = res.list
                }
            }).catch(res => {
                console.log(res)
            })
        },
        // risk 初始化
        initRiskData() {
            this.riskCategoryForm = {}
            this.riskTypeList = []
            this.riskTypeForm = {}
            this.riskLevelList = []
            this.riskLevelForm = {}
            this.riskDisposeDateList = []
            this.riskDisposeDateForm = {}
            this.riskDetailsList = []
            this.riskDetailsForm = {}
        }
    }
}
